package com.atguigu.Aspect;


import com.atguigu.Annoton.myannotion;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;
import java.util.concurrent.CompletionStage;

@Slf4j
@Aspect
@Component
public class aspect {


//    @Around("@annotation(com.atguigu.Annoton.myannotion)")
    @Around("@annotation(com.atguigu.Annoton.myannotion)")
    public Object logaround(ProceedingJoinPoint proceedingJoinPoint)throws Throwable{
        Object result = null;

        MethodSignature methodSignature=(MethodSignature)proceedingJoinPoint.getSignature();
        Method method = methodSignature.getMethod();

        myannotion myannotion = method.getAnnotation(myannotion.class);
        if (myannotion!=null && myannotion.enable()){
            long startTime = System.currentTimeMillis();
            System.out.print("环绕通知方法前："+proceedingJoinPoint.getSignature().getName());
            result = proceedingJoinPoint.proceed();
            System.out.print("环绕通知方法后："+proceedingJoinPoint.getSignature().getName());

            long endTime = System.currentTimeMillis();
            System.out.println("-------costTime: "+(endTime-startTime)+"毫秒");
            return result;
        }else{
            return proceedingJoinPoint.proceed();
        }


    }
}
